package com.hbzd.protection.controller;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.sword.wechat4j.event.MsgType;

import com.hbzd.protection.util.MyWechat;


@Controller
@RequestMapping("/message")
public class MessageController {
	
	/**
	 * 消息处理
	 * @param request
	 * @param response
	 */
	@RequestMapping(method=RequestMethod.POST,value="/deal"  )
	public void messageDeal(HttpServletRequest request, HttpServletResponse response) {
		// 消息处理
		MyWechat myWechat = new MyWechat(request);
		String result = myWechat.execute();
		try {
			response.getOutputStream().write(result.getBytes());
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	/**
	 * 认证
	 * @param request
	 * @param response
	 */
	@RequestMapping(method=RequestMethod.GET,value="/deal"  )
	public void authenticate(HttpServletRequest request, HttpServletResponse response) {
		//签名
		MyWechat myWechat = new MyWechat(request);
		String result = myWechat.execute();
		System.out.println(result);
		try {
			response.getOutputStream().write(result.getBytes());
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
